package com.czl.base.util

import android.app.Activity
import androidx.fragment.app.Fragment
import com.luck.picture.lib.PictureSelector
import com.luck.picture.lib.config.PictureConfig
import com.luck.picture.lib.config.PictureMimeType
import com.luck.picture.lib.entity.LocalMedia
import com.luck.picture.lib.listener.OnResultCallbackListener

/**
 *
 * @Description:
 * @Author: XCH
 * @CreateDate: 2022/1/27 15:39
 */
object ChoiceImgHelper {

    fun ChoiceImg(
        activity: Activity,
        resultFunc: (result: List<LocalMedia?>) -> Unit?,
        cancelFunc: () -> Unit?
    ) {
        PictureSelector.create(activity)
            .openGallery(PictureMimeType.ofImage())
            .imageEngine(GlideEngine.createGlideEngine())
            .isCompress(true)
            .selectionMode(PictureConfig.SINGLE)
            .minimumCompressSize(100)
            .forResult(object : OnResultCallbackListener<LocalMedia?> {
                override fun onResult(result: List<LocalMedia?>) {
                    resultFunc(result)
                }

                override fun onCancel() {
                    cancelFunc
                }
            })
    }

    fun ChoiceImg(
        activity: Fragment,
        resultFunc: (result: List<LocalMedia?>) -> Unit,
        cancelFunc: () -> Unit?
    ) {
        PictureSelector.create(activity)
            .openGallery(PictureMimeType.ofImage())
            .imageEngine(GlideEngine.createGlideEngine())
            .isCompress(true)
            .selectionMode(PictureConfig.SINGLE)
            .minimumCompressSize(100)
            .forResult(object : OnResultCallbackListener<LocalMedia?> {
                override fun onResult(result: List<LocalMedia?>) {
                    resultFunc(result)
                }

                override fun onCancel() {
                    cancelFunc
                }
            })
    }
}